package cn.tedu.ivosback.maintenance.controller;

import cn.tedu.ivosback.base.response.JsonResult;
import cn.tedu.ivosback.maintenance.pojo.dto.MaintenanceParam;
import cn.tedu.ivosback.maintenance.pojo.dto.MaintenanceQuery;
import cn.tedu.ivosback.maintenance.pojo.vo.MaintenanceVO;
import cn.tedu.ivosback.maintenance.service.MaintenanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/maintenance")
public class MaintenanceController {
    @Autowired
    MaintenanceService maintenanceService;

    @GetMapping("select")
    public JsonResult select(MaintenanceQuery maintenanceQuery) {
        log.debug("开始处理查询维修记录的Controller层：{}", maintenanceQuery);
        List<MaintenanceVO> list = maintenanceService.select(maintenanceQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult save(MaintenanceParam maintenanceParam) {
        log.debug("开始处理添加维修记录的Controller层：{}", maintenanceParam);
        maintenanceService.save(maintenanceParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id) {
        log.debug("开始处理删除维修记录的Controller层：{}", id);
        maintenanceService.delete(id);
        return JsonResult.ok();
    }
}
